package com.example.myzhugezhaofang.adapter.newhouse;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myzhugezhaofang.R;
import com.example.myzhugezhaofang.bean.newhouse.HouseListBean;

import java.util.List;

/**
 * 作者：朱勇闯
 * data : 2021/4/11  19:17
 * 作用： xxxx
 */
public class TagsAdapter extends RecyclerView.Adapter {
    private Context context;
    private List<HouseListBean.DataBean.DataBeans.TagBean> tags;

    public TagsAdapter(Context context, List<HouseListBean.DataBean.DataBeans.TagBean> tags) {
        this.context = context;
        this.tags = tags;
    }

    @NonNull
    @Override
    public HomeHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(context).inflate(R.layout.item_tag_like, parent, false);
        return new HomeHolder(v);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        HomeHolder holder1 = (HomeHolder) holder;

        holder1.tv.setText(tags.get(position).getName());
        String color = tags.get(position).getTitleColor();
        String bgColor = tags.get(position).getBgColor();
        int color1 = Color.parseColor(color);
        int bg = Color.parseColor(bgColor);
        holder1.tv.setTextColor(color1);
        holder1.tv.setBackgroundColor(bg);
    }

    @Override
    public int getItemCount() {
        return tags.size();
    }

    public static class HomeHolder extends RecyclerView.ViewHolder {
        private TextView tv;

        public HomeHolder(@NonNull View itemView) {
            super(itemView);
            tv = itemView.findViewById(R.id.tv_tags_like);
        }
    }
}
